home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / Enemy.as < prev    next >
Text File  |  2013-04-24  |  3KB  |  99 lines

  1. class Enemy extends MovieClip
  2. {
  3.    function Enemy()
  4.    {
  5.       super();
  6.       this._damage = 1;
  7.       this._life = 2;
  8.       this._holdMovement = true;
  9.       this.enemyIncrem2 = 0;
  10.       this.enemySetBase2 = _global.FPSforTweenClass * 1;
  11.       this._dead = false;
  12.    }
  13.    function onEnterFrame()
  14.    {
  15.       this.rotateEnemy();
  16.       this.enemyShoot();
  17.       this.enemyDie();
  18.    }
  19.    function enemyDie()
  20.    {
  21.       var i = 0;
  22.       while(i < _root.arrBullets.length)
  23.       {
  24.          var ObjRef = eval("_root." + _root.arrBullets[i]);
  25.          if(this.hitTest(ObjRef._x,ObjRef._y))
  26.          {
  27.             if(!ObjRef._enemy)
  28.             {
  29.                var rotRan = 1 + Math.floor(Math.random() * 360);
  30.                if(this._life >= 1)
  31.                {
  32.                   var hitAnName = "shield_hits" + _root.getNextHighestDepth();
  33.                   _root.attachMovie("shield_hits",hitAnName,_root.getNextHighestDepth());
  34.                   _root[hitAnName]._x = ObjRef._x;
  35.                   _root[hitAnName]._y = ObjRef._y;
  36.                   _root[hitAnName]._rotation = rotRan;
  37.                }
  38.                if(this._life > 0)
  39.                {
  40.                   _root.removeCallback(_root.arrBullets[i]);
  41.                   _root[_root.arrBullets[i]].removeMovieClip();
  42.                   _root.arrBullets.splice(i,1);
  43.                   this._life--;
  44.                }
  45.                else
  46.                {
  47.                   this._dead = true;
  48.                   _root.removeCallback(_root.arrBullets[i]);
  49.                   _root[_root.arrBullets[i]].removeMovieClip();
  50.                   _root.arrBullets.splice(i,1);
  51.                   var deathAnimationName = "death_" + _root.getNextHighestDepth();
  52.                   _root.enemyLayer.attachMovie("enemy_1_death",deathAnimationName,_root.getNextHighestDepth());
  53.                   _root.enemyLayer[deathAnimationName]._x = this._x;
  54.                   _root.enemyLayer[deathAnimationName]._y = this._y;
  55.                   _root.enemyLayer[deathAnimationName]._rotation = rotRan;
  56.                   _root.ReportEnemyDeath(this._name);
  57.                   this.removeMovieClip();
  58.                }
  59.             }
  60.          }
  61.          i++;
  62.       }
  63.    }
  64.    function dieNow()
  65.    {
  66.       trace("die now called");
  67.       _root.killAllAnimations(this._x,this._y);
  68.       this.removeMovieClip();
  69.    }
  70.    function rotateEnemy()
  71.    {
  72.       if(!this._dead)
  73.       {
  74.          var _loc3_ = new Vector();
  75.          _loc3_._x = _root.pointer._x - this._x - _root.enemyLayer._x;
  76.          _loc3_._y = _root.pointer._y - this._y - _root.enemyLayer._y;
  77.          var _loc4_ = Math.atan2(_loc3_._y,_loc3_._x);
  78.          var _loc5_ = 360 * _loc4_ / 6.283185307179586;
  79.          this._rotation = _loc5_;
  80.       }
  81.       else
  82.       {
  83.          this._rotation = this._rotation;
  84.       }
  85.    }
  86.    function enemyShoot()
  87.    {
  88.       if(this.enemyIncrem2 >= this.enemySetBase2)
  89.       {
  90.          var _loc3_ = new Vector();
  91.          _loc3_._x = Math.cos(3.141592653589793 * this._rotation / 180) * 7;
  92.          _loc3_._y = Math.sin(3.141592653589793 * this._rotation / 180) * 7;
  93.          _root.shootEnemyGun(_loc3_._x,_loc3_._y,this._x + _root.arena._x,this._y + _root.arena._y);
  94.          this.enemyIncrem2 = 0;
  95.       }
  96.       this.enemyIncrem2 = this.enemyIncrem2 + 1;
  97.    }
  98. }
  99.